package com.dong.mcd.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * hashCode生成类，用于对手机端传过来的hashcode进行验证
 * @author xuxh
 * @company eshore
 * @date 2013-4-1
 */
public class MD5Util {

	/**
	 * 针对text字符串进行编码并返回编码后的值
	 * @param text
	 * @return
	 */
	public static String md5Digest(String text) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(text.getBytes());
			byte[] b = md.digest();
			String result = "";
			String temp = "";
			for (int i = 0; i < 16; i++) {
				temp = Integer.toHexString(b[i] & 0xFF);
				if (temp.length() == 1)
					temp = "0" + temp;
				result += temp;
			}
			result = result.toLowerCase();
			return result;
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
}
